// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import Music, {musicName} from "../PublicScript/Music";
import Money from "./Money";
import ControlScript from "../PublicScript/ControlScript";
import LoadShow from "./LoadShow";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Share extends cc.Component {

    @property(cc.SpriteFrame)
    spriteFrame: cc.SpriteFrame[] = [];

    @property(cc.Sprite)
    sprite: cc.Sprite = null;

    // onLoad () {}

    start () {

    }

    state = false;
    setCallback(state){
        this.state = state;
        this.sprite.spriteFrame = this.state ? this.spriteFrame[0] : this.spriteFrame[1]
    }

    onClick(e, d){
        Music.GamePlayEffect(musicName.click);
        if(parseInt(d) == 1){
            Money.addMoney(200);
            ControlScript.createToast("获得200金币！");
            this.loadOver();
        }
        if(parseInt(d) == 2){
            this.loadOver();
        }
    }

    loadOver(){
        ControlScript.instantiate("loadShow", (view)=>{
            view.getComponent(LoadShow).show("gameOver", true, this.state);
            this.node.destroy();
        })
    }

    // update (dt) {}
}
